import { defineStore } from 'pinia'
export const useUser = defineStore('userStore', {
  state: () => ({
    token: null as string | null,
    userInfo: {}
  }),
  getters: {
    get: (state) => {
      return {
        token: state.token,
        userInfo: state.userInfo
      }
    }
  },
  actions: {
    setToken (token: string | null) {
      this.token = token
    },
    setUserInfo (userInfo: any) {
      this.userInfo = userInfo
    },
    // 退出登录
    loginOut (): void {
      this.token = null
      this.userInfo = {}
    }
  },
  persist: {
    // storage: sessionStorage,
    paths: ['token', 'userInfo']
  }
})
